<?php
namespace Badmins\Controller;
use Think\Controller;
class ArticleController extends Controller {
    public function index(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$where = array();
    	$status = I('class_id/d');
    	if($status){
    		$where['class_id'] = $status;
    	}
    	$name = I('name');
    	if(!empty($name)){
    		$where['title'] = array('like',"%{$name}%");
    	}
    	$start_time = I('start_time');
    	if($start_time){
    		
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$db = M('article');
    	$count = $db->where($where)->count();
    	$firstrow = ($p-1)*$listrow;
    	$list = lists('article','',$where,"*","id desc",$firstrow,$listrow,2);
    	if(!empty($list)){
    		foreach ($list as $i=>$va){
    			if($va['class_id']){
    				$list[$i]['classname'] = M('class_article')->where("id='{$va['class_id']}'")->getField('name');
    			}else{
    				$list[$i]['classname'] = "无分类";
    			}
    		}
    	}
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$where['status'] = 0;
    	$res = lists('class_article','',$where,'*','id desc',0,0,2);
    	$res = \Org\Oa\common::sortdata($res,0,'--');
    	$this->assign('res',$res);
        $this->display();
    }
    /**
     * 分类列表
     */
    public function type(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$count = M('class_article')->count();
    	$firstrow = ($p-1)*$listrow;
    	$list = lists('class_article','',1,"*","id desc",$firstrow,$listrow,2);
    	$list = \Org\Oa\common::sortdata($list);
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 专题
     */
    public function sub(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$where = array();
    	$name = I('name');
    	if(!empty($name)){
    		$where['title'] = array('like',"%{$name}%");
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$db = M('subject');
    	$count = $db->where($where)->count();
    	$firstrow = ($p-1)*$listrow;
    	$list = lists('subject','',$where,"*","id desc",$firstrow,$listrow,2);
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$this->display();
    }

}